package com.yn.front.zy;


import com.yn.common.request.zyorder.ZyOrderRequest;
import com.yn.common.response.zyorder.ZyOrderQuoteResponse;
import com.yn.common.utils.genutils.CommonResult;
import com.yn.service.service.UserService;
import com.yn.service.service.ZyOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 转运订单
 */
@Slf4j
@RestController()
@RequestMapping("api/zy/order")
@Api(tags = "转运订单")
public class ZyOrderController {

    @Autowired
    private ZyOrderService zyOrderService;

    @Autowired
    private UserService userService;

    /**
     * 订单支付
     */
    @ApiOperation(value = "转运提交订单")
    @RequestMapping(value = "/submitZyOrder", method = RequestMethod.POST)
    public CommonResult<ZyOrderQuoteResponse> submitZyOrder(@RequestBody @Validated ZyOrderRequest zyOrderRequest) {
       /* String ip = CrmebUtil.getClientIp(request);
        return CommonResult.success(orderPayService.payment(orderPayRequest, ip));*/
        log.info("转运提交订单入参：{}", zyOrderRequest);
        ZyOrderQuoteResponse zyOrderQuoteResponse = zyOrderService.addOrder(zyOrderRequest, true);
        return CommonResult.success(zyOrderQuoteResponse);
    }

    /**
     * 获取报价单
     */
    @ApiOperation(value = "获取报价单")
    @RequestMapping(value = "/getQuote", method = RequestMethod.POST)
    public CommonResult<ZyOrderQuoteResponse> getQuote(@RequestBody @Validated ZyOrderRequest zyOrderRequest) {
       /* String ip = CrmebUtil.getClientIp(request);
        return CommonResult.success(orderPayService.payment(orderPayRequest, ip));*/
        log.info("获取报价单入参：{}", zyOrderRequest);
        ZyOrderQuoteResponse zyOrderQuoteResponse = zyOrderService.getQuote(zyOrderRequest);
        return CommonResult.success(zyOrderQuoteResponse);
    }

    @ApiOperation(value = "查询转运订单详情")
    @GetMapping(value = "/getZyOrderDetail")
    public CommonResult<ZyOrderQuoteResponse> getZyOrderDetail(String orderNo) {
        log.info("查询转运订单详情入参：{}", orderNo);
        ZyOrderQuoteResponse zyOrderQuoteResponse = zyOrderService.getZyOrderDetail(orderNo);
        return CommonResult.success(zyOrderQuoteResponse);
    }

    //取消订单
    @ApiOperation(value = "取消订单")
    @GetMapping(value = "/cancelOrder")
    public CommonResult<String> cancelOrder(String orderNo) {
        log.info("取消订单入参：{}", orderNo);
        zyOrderService.cancelOrder(orderNo);
        return CommonResult.success();
    }

    @ApiOperation(value = "删除订单")
    @DeleteMapping(value = "/del")
    public CommonResult<String> del( String orderNos) {
        Integer userId = userService.getUserId();
        zyOrderService.del(orderNos,userId);
        return CommonResult.success();
    }

}



